//
//  AppDelegate.m
//  HYHOME
//
//  Created by Mac on 16/1/20.
//  Copyright © 2016年 Mac. All rights reserved.
//


#import "Strategy.h"
#import "AppDelegate.h"
#import "LeftMenu.h"
#import "Items.h"
#import "ViewController.h"
#import "News.h"
#import "TB.h"
#import "SetUp.h"
#import "DKNightVersion.h"
#import "DataBaseHandle.h"
#import "Personal.h"
@interface AppDelegate ()<UIScrollViewDelegate>
@property (nonatomic,retain)NSMutableArray  *arrayOfImageView;
@property (nonatomic,retain)UIScrollView *scrollView;
@property (nonatomic,retain)UIPageControl *pageControl;
@property (nonatomic,retain)UIButton *buttonOfStart;
@end

@implementation AppDelegate


- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
    // Override point for customization after application launch.
    
    self.window = [[UIWindow alloc]initWithFrame:[UIScreen mainScreen].bounds];
    
    
    self.window.backgroundColor = [UIColor whiteColor];
    

    ViewController *vc =  [[ViewController alloc]init];
    Items *items = [[Items alloc] init];
    News *news = [[News alloc] init];
    Personal *person = [[Personal alloc]init];
    Strategy *strategy = [[Strategy alloc]init];
    
    UINavigationController *navi = [[UINavigationController alloc] initWithRootViewController:vc];
    
    UINavigationController *navi2 = [[UINavigationController alloc] initWithRootViewController:items];
    
    
    UINavigationController *navi3 = [[UINavigationController alloc] initWithRootViewController:news];
  
    UINavigationController *navi4 = [[UINavigationController alloc]initWithRootViewController:person];

    UINavigationController *navi5 = [[UINavigationController alloc]initWithRootViewController:strategy];
    
    // tableBarController
    
    TB *tb = [TB TBShare];
    
    tb.tabBar.tintColor = [UIColor cyanColor];

    navi.tabBarItem = [[UITabBarItem alloc]initWithTitle:@"首页" image:[UIImage imageNamed:@"first"] tag:100];
    
    items.tabBarItem = [[UITabBarItem alloc]initWithTitle:@"单品" image:[UIImage imageNamed:@"shangpin"] tag:200];
    
    
    news.tabBarItem = [[UITabBarItem alloc]initWithTitle:@"最新" image:[UIImage imageNamed:@"zuixin"] tag:300];
    
    person.tabBarItem =[[ UITabBarItem alloc]initWithTitle:@"个人中心" image:[UIImage imageNamed:@"iconfont-gerenzhongxin"] tag:400];

    
    strategy.tabBarItem = [[UITabBarItem alloc]initWithTitle:@"攻略" image:[UIImage imageNamed:@"gonglve"] tag:500];
    tb.viewControllers = @[navi,navi2,navi5,navi3,navi4];
    tb.tabBar.dk_barTintColorPicker = DKColorWithRGB(0xffffff, 0x343434);

    
    LeftMenu *left = [[LeftMenu alloc]init];
    
    
    RESideMenu *sideMenuViewController = [[RESideMenu alloc]initWithContentViewController:tb leftMenuViewController:left rightMenuViewController:nil];
  
    
    sideMenuViewController.backgroundImage = [UIImage imageNamed:@"beijing.jpg"];
    sideMenuViewController.menuPreferredStatusBarStyle = 1; // UIStatusBarStyleLightContent
    sideMenuViewController.delegate = self;
    
    sideMenuViewController.contentViewShadowColor = [UIColor blackColor];
    sideMenuViewController.contentViewShadowOffset = CGSizeMake(0, 0);
    sideMenuViewController.contentViewShadowOpacity = 0.6;
    sideMenuViewController.contentViewShadowRadius = 12;
    sideMenuViewController.contentViewShadowEnabled = YES;
    
    self.window.rootViewController = sideMenuViewController;
    self.window.backgroundColor = [UIColor whiteColor];
    [self.window makeKeyAndVisible];
    NSLog(@"%@", NSHomeDirectory());
    // 第一次进入
    if (![[NSUserDefaults standardUserDefaults] boolForKey:@"引导页"]) {
        
        [[NSUserDefaults standardUserDefaults] setBool:1 forKey:@"引导页"];
        
        self.arrayOfImageView = [NSMutableArray array];
        self.arrayOfImageView = @[@"Y1.jpg", @"Y2.jpg", @"Y3.jpg"].mutableCopy; //添加引导页图片
        //
        self.scrollView = [[UIScrollView alloc] init];
        [self.window addSubview:self.scrollView];  //注意:添加在window上
        [_scrollView release];
        self.scrollView.pagingEnabled = YES;
        self.scrollView.showsHorizontalScrollIndicator = NO;
        self.scrollView.userInteractionEnabled = YES;
        self.scrollView.frame = self.window.frame;
        self.scrollView.contentSize = CGSizeMake(self.window.frame.size.width * self.arrayOfImageView.count, 0);
        self.scrollView.delegate = self;
        
        self.pageControl = [[UIPageControl alloc] init];
        [self.window addSubview:self.pageControl];
        [_pageControl release];
        self.pageControl.frame = CGRectMake(0, 0, self.window.frame.size.width / 2, 40);
        self.pageControl.center = CGPointMake(self.scrollView.frame.size.width / 2, self.scrollView.frame.size.height - 40);
        self.pageControl.numberOfPages = self.arrayOfImageView.count;
        
        //for循环, 在scrollView上添加照片
        for (int i = 0; i < self.arrayOfImageView.count; i++) {
            UIImageView *imageView1 = [[UIImageView alloc] initWithImage:[UIImage imageNamed:self.arrayOfImageView[i]]];
            imageView1.frame = CGRectMake(self.scrollView.frame.size.width * i, 0, self.scrollView.frame.size.width, self.scrollView.frame.size.height);
            imageView1.tag = i;
            [self.scrollView addSubview:imageView1];
            imageView1.userInteractionEnabled = YES;
            
        }
        
                //引导页最后一页"开始体验"按钮, 进入APP
                self.buttonOfStart = [UIButton buttonWithType:UIButtonTypeCustom];
                UIImageView *image = [self.window viewWithTag:2];
                [image addSubview:self.buttonOfStart];
                [self.buttonOfStart setTitle:@"开始体验" forState:UIControlStateNormal];
                self.buttonOfStart.layer.borderWidth = 1;
                self.buttonOfStart.layer.borderColor = [[UIColor whiteColor] CGColor];
                self.buttonOfStart.layer.cornerRadius = 7;
                self.buttonOfStart.layer.masksToBounds = YES;
                self.buttonOfStart.frame = CGRectMake(0, 0, self.window.frame.size.width / 2, 40);
                self.buttonOfStart.center = CGPointMake(self.window.frame.size.width / 2, self.window.frame.size.height - 100);
        [self.buttonOfStart addTarget:self action:@selector(start:) forControlEvents:UIControlEventTouchUpInside];
        
    }
    
    
    
    
    
    if ([[NSUserDefaults standardUserDefaults] boolForKey:@"ISNIGHT"]) {
        [DKNightVersionManager nightFalling];
    }else {
        [DKNightVersionManager dawnComing];
        
    }
    
  
    [self.scrollView release];
    [_window release];
    [items release];
    [news release];
    [navi release];
    [navi2 release];
    [navi3 release];
    [left release];
    [sideMenuViewController release];
    
    
    
    
    
    [[DataBaseHandle shareDataBaseHandle] open];
    [[DataBaseHandle shareDataBaseHandle] createTable];
    

    
    
    return YES;
}

- (void)start:(UIButton *)button{

    [self.pageControl removeFromSuperview];
    [self.scrollView removeFromSuperview];


}

#pragma mark RESideMenu Delegate

- (void)sideMenu:(RESideMenu *)sideMenu willShowMenuViewController:(UIViewController *)menuViewController
{
 
}

- (void)sideMenu:(RESideMenu *)sideMenu didShowMenuViewController:(UIViewController *)menuViewController
{
}

- (void)sideMenu:(RESideMenu *)sideMenu willHideMenuViewController:(UIViewController *)menuViewController
{
}

- (void)sideMenu:(RESideMenu *)sideMenu didHideMenuViewController:(UIViewController *)menuViewController
{
}





-(void)dealloc{
    [_window release];
    [super dealloc];
    
    
}




- (void)applicationWillResignActive:(UIApplication *)application {
    // Sent when the application is about to move from active to inactive state. This can occur for certain types of temporary interruptions (such as an incoming phone call or SMS message) or when the user quits the application and it begins the transition to the background state.
    // Use this method to pause ongoing tasks, disable timers, and throttle down OpenGL ES frame rates. Games should use this method to pause the game.
}

- (void)applicationDidEnterBackground:(UIApplication *)application {
    // Use this method to release shared resources, save user data, invalidate timers, and store enough application state information to restore your application to its current state in case it is terminated later.
    // If your application supports background execution, this method is called instead of applicationWillTerminate: when the user quits.
}

- (void)applicationWillEnterForeground:(UIApplication *)application {
    // Called as part of the transition from the background to the inactive state; here you can undo many of the changes made on entering the background.
}

- (void)applicationDidBecomeActive:(UIApplication *)application {
    // Restart any tasks that were paused (or not yet started) while the application was inactive. If the application was previously in the background, optionally refresh the user interface.
}

- (void)applicationWillTerminate:(UIApplication *)application {
    // Called when the application is about to terminate. Save data if appropriate. See also applicationDidEnterBackground:.
}

@end
